const NoteService = require('../services/NoteService');
const NoteController = {
    getAllNotes: async (req, resp) => {
        const currentUid = req.session.uid;
        const queryResult = await NoteService.getAllNotes(currentUid);
        resp.send(queryResult);
    },
    getSelectedNote: async (req, resp) => {
        const nid = req.params["nid"];
        console.log('这是nid', nid);
        const queryResult = await NoteService.getSelectedNote(nid);
        resp.send(queryResult);
    },
    saveNoteByNid: async (req, resp) => {
        const { nid, content, title, date, backgroundColor } = req.body;
        const saveResult = await NoteService.saveNoteByNid(nid, content, title, date, backgroundColor);
        if (saveResult === 1) {
            resp.send({ ok: 1 });
        } else {
            resp.send({ ok: 0 });
        }
    },
    newNoteByUid: async (req, resp) => {
        const { uid, date } = req.body;
        const newResult = await NoteService.newNoteByUid(uid, date);
        if (newResult === 1) {
            resp.send({ ok: 1 });
        } else {
            resp.send({ ok: 0 });
        }
    },
    deleteNoteByNid: async (req, resp) => {
        const nid = req.params["nid"];
        const deleteResult = await NoteService.daleteNoteByNid(nid);
        if (deleteResult === 1) {
            resp.send({ ok: 1 });
        } else {
            resp.send({ ok: 0 });
        }
    }
}
module.exports = NoteController